//
//  MYNewsShopHotelMoreListVC.m
//  MuYing
//
//  Created by tbb on 2020/3/9.
//  Copyright © 2020 TBB. All rights reserved.
//

#import "MYNewsShopHotelMoreListVC.h"
#import "MYNewsShopDetailsModel.h"
#import "MYNewsShopDetailsCalendar.h"
#import "MYNewsShopDetailsHotelOrderVC.h"
@interface MYNewsShopHotelMoreListVC ()

@end

@implementation MYNewsShopHotelMoreListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = kYQLS(@"选择类型");
    kYQREGISTERTABLEVIEWNIBCELL(@"MYNewsShopDetailsGoodsCell")
    kYQREGISTERTABLEVIEWCNIBHeaderFooter(@"MYNewsShopDetailsGoodsHeader")
}
-(void)setDetailsModel:(MYNewsShopDetailsModel *)detailsModel {
    _detailsModel = detailsModel;
    [self.listTableView reloadData];
}

-(void)selectDateAction:(UIButton *)sender {
    ws(self);
    [MYNewsShopDetailsCalendar showCalenderViewDate1:self.startDate date2:self.leaveDate allowsMultipleSelection:YES selectDateBlock:^(NSDate * _Nonnull inCheckInDate, NSDate * _Nonnull leaveDate) {
        weakself.startDate = inCheckInDate;
        weakself.leaveDate = leaveDate;
        [weakself.listTableView reloadData];
    }];
}

-(void)hotelGoToPayVC:(MYNewsShopDetailsStandardModel *) standardModel {
    MYNewsShopDetailsHotelOrderVC *payVC = [MYNewsShopDetailsHotelOrderVC new];
    payVC.standardModel = standardModel;
    payVC.detailsModel = self.detailsModel;
    payVC.startDate = self.startDate;
    payVC.leaveDate = self.leaveDate;
    kYQPUSH(payVC);
}
#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.detailsModel.standardList.count;
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    MYNewsShopDetailsGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MYNewsShopDetailsGoodsCell"];
    MYNewsShopDetailsStandardModel * standardModel = nil;
    if (indexPath.row < self.detailsModel.standardList.count) {
        standardModel = self.detailsModel.standardList[indexPath.row];
    }
    cell.standardModel = standardModel;
    ws(self);
    cell.reserveActionBlock = ^(MYNewsShopDetailsStandardModel * standardModel) {
        [weakself hotelGoToPayVC:standardModel];
    };

    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 112;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    MYNewsShopDetailsGoodsHeader *goodsHeader = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"MYNewsShopDetailsGoodsHeader"];
     [goodsHeader.selectDateBtn addTarget:self action:@selector(selectDateAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [goodsHeader.selectDateBtn addTarget:self action:@selector(selectDateAction:) forControlEvents:(UIControlEventTouchUpInside)];

    NSInteger day = [NSDate pleaseInsertStarDate:self.startDate andInsertEndDate:self.leaveDate].day;
    
    NSString *str1 = [NSDate getDateToString:self.startDate format:@"MM月dd日"];
    NSString *str2 = [NSDate getDateToString:self.leaveDate format:@"MM月dd日"];
    goodsHeader.titleLb.text = [NSString stringWithFormat:@"%@ %@(%zd%@)",str1,str2,day,kYQLS(@"晚")];
    return goodsHeader;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 45;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001;
}

#pragma mark - UITableViewDelegate, UITableViewDataSource end

@end
